package com.bigmi.schedule.feign;

import com.bigmi.apis.schedule.CheduleClientIP;
import com.bigmi.model.common.dtos.ResponseResult;
import com.bigmi.model.schedule.dto.Task;
import com.bigmi.schedule.service.TaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class CheduleClient implements CheduleClientIP {

    @Autowired
    private TaskService taskService;
    //添加延时任务
    @PostMapping("api/v1/task/add")
    public ResponseResult addTask(@RequestBody Task task){

        return ResponseResult.okResult(taskService.addTask(task)) ;
    }
    //取消任务
    @GetMapping("api/v1/task/{taskId}")
    public ResponseResult cancelTask(@PathVariable("taskId") long taskId) {
        return ResponseResult.okResult(taskService.cancelTask(taskId));
    }
    //按照优先级拉取任务
    @GetMapping("api/v1/task/{type}/{priority}")
    public ResponseResult poll(@PathVariable("type") int type ,@PathVariable("priority") int priority) {
        return ResponseResult.okResult(taskService.poll(type,priority));
    }
}
